<%--
  Created by IntelliJ IDEA.
  User: dailyblue
  Date: 2025/7/19
  Time: 09:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" language="java" %>
<html>
<head>
    <title>Title</title>
    <%
        // 如果没有登陆跳转到login.jsp
        Cookie[] cookies = request.getCookies();
        if (cookies == null || cookies.length == 0) {
            Cookie error = new Cookie("ERROR", "需要登陆后访问");
            response.addCookie(error);
            response.sendRedirect("login.jsp");
            return;
        }
        boolean flag = false;
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("username")) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            Cookie error = new Cookie("ERROR", "需要登陆后访问");
            response.addCookie(error);
            response.sendRedirect("login.jsp");
            return;
        }
    %>
</head>
<body>
<h3>主页</h3>
<h4>欢迎：${cookie.nickname.value}</h4>

<a href="../logout_cookie">注销</a>
</body>
</html>
